@model Category
@using (Ajax.BeginAjaxForm("Edit", "Category", new jQueryAjaxOptions()
   {
       HttpMethod = "POST",
       AutoBlocking = true,
       OnComplete = "var _n=$('#CategoryTree').dtree('option','selectedNode'); $(_n).children(\".d-treenode-content\").find(\".d-treenode-text\").text($('#Category_Title').val());"
   },
       new RouteValueDictionary(new { Area = "Publishing", id = Model.ID })))
{
    <div style="padding: 10px;">
        <h3>
            <img style="float: left;" src="@Url.Content("~/Content/Images/Publishing/folder_full.png")"
            alt="" /><span style="float: left; margin-top: 8px;">@Model.Title</span></h3>
    </div>
    @Html.AntiForgeryToken() 
    <table cellspacing="0" class="d-field-table" style="border: 1px solid #cccccc;">
        <tr>
            <td valign="top">
                <h3 class="d-field-title">
                    <label for="Category_Title">
                        @Html.Global("RES_TITLE")
                    </label>
                </h3>
                <div class="d-field-description">
                    @Html.Global("publishing", "CategoryTitleTips")
                </div>
            </td>
            <td>
                @Ajax.DnaFor().TextBox(m => m.Title).Width(250).GetHtml()
                <input name="Category.IsModerated" type="hidden" value="false" />
                <input name="Category.EnabledVersioning" type="hidden" value="false" />
            </td>
        </tr>
        <tr>
            <td valign="top">
                <h3 class="d-field-title">
                    @Html.Global("publishing", "AllowAnonymousePostComments")
                </h3>
                <div class="d-field-description">
                    @Html.Global("publishing", "AllowAnonymousePostCommentsTips")</div>
            </td>
            <td>
                @Ajax.DnaFor().CheckBox(m => m.AllowAnonymousPostComment, Url.Content("~/content/images/icon_accept_16.png"),
                   Url.Content("~/content/images/icon_block_16.png")).LocText("publishing", "Allow").GetHtml()
            </td>
        </tr>
        <tr>
            <td>
                <h3 class="d-field-title">
                    @Html.Global("RES_IMAGE")</h3>
                <div class="d-field-description">
                      @Html.Global("publishing", "CategoryImageTips")
                </div>
            </td>
            <td>
                <table>
                    <tr>
                        <td>
                            @Ajax.DnaFor().TextBox(m => m.ImageUrl).Width(300).GetHtml()
                        </td>
                        <td>
                            @Ajax.Dna().Button("btnBrowseLogo").LocText("RES_BROWSE").Click("_fileDlg(\"#Category_ImageUrl\");").ImageIcons(Url.Content("~/content/images/icon_folder_open_16.gif")).GetHtml()
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <h3 class="d-field-title">
                    <label for="Category_Description">
                        @Html.Global("RES_DESC")
                    </label>
                </h3>
                <div class="d-field-description">
                    @Html.Global("publishing", "CategoryDescriptTips")</div>
            </td>
            <td>
                @Ajax.DnaFor().TextArea(m => m.Description).Width(420).Height(208).Resizable().GetHtml()
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                @Ajax.Dna().Button("btnCreateNewCategory").Submit().ImageIcons(Url.Content("~/content/images/icon_save.gif")).LocText("RES_SAVE").GetHtml()
                @Ajax.Dna().Button("btnDeleteCategory").LocText("RES_DELETE").ImageIcons(Url.Content("~/content/images/icon_delete_file_16.png")).Click(Ajax.GeneratejQueryAjaxScripts(new jQueryAjaxOptions()
                                {
                                    HttpMethod = "POST",
                                    Url = Url.Action("Delete", "Category", new { Area = "Publishing", id = Model.ID }),
                                    Confirm = string.Format(Html.Global("publishing", "CategoryDeleteConfirm"), Model.Title),
                                    OnComplete = "_deleteEditingCategory();"
                                })).GetHtml()
                @Ajax.Dna().Button("btnViewCategory").Click("open(\"" + new CategoryWrapper(Model).PermaLink + "\");").ImageIcons(Url.Content("~/content/images/icon_blog_16.gif")).Text("View").GetHtml()
            </td>
        </tr>
    </table>
}
<script type="text/javascript">
    function _deleteEditingCategory() {
        var _n = $("#CategoryTree").dtree("option", "selectedNode");
        if (_n) {
            if ($(_n).attr("key") == $("#CategoryTree").children(".d-treenode").first().attr("key"))
                return;

            var prevNode = $(_n).prev();
            var pn = $(_n).parent().closest(".d-treenode");
            $(_n).remove();
            if (prevNode.length)
                $("#CategoryTree").dtree("select", prevNode); else {
                if (pn.length) $("#CategoryTree").dtree("select", pn);
            }
        }
    }
</script>
@Html.StartupScripts()
<script type="text/javascript">
    function _fileDlg(_el) {
      $dna.fileDlg("@Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name })", _el);
    }
</script>
